package com.authine.cloudpivot.ext.vo;

import com.authine.cloudpivot.ext.model.order.CustomerOrderGoodsVo;
import com.authine.cloudpivot.ext.utils.Utils;
import com.authine.mvp.app.org.dto.domainmodel.UnitType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Optional;

/**
 * 订单商品VO
 * Created by Kris Wang on 2018/5/28.
 *
 * @author update 张磊
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("订单商品")
public class OrderGoodsVo implements Serializable {

    private static final long serialVersionUID = -4494303158417183258L;
    @ApiModelProperty(value = "商城商品ID", example = "91738", required = true, position = 1)
    private String goodsId;
    @ApiModelProperty(value = "商品来源类型 1 固买商城，2 寻源商品, 3 企业商城, 4 外部商城订单", example = "3", required = true, position = 2)
    private Integer src;
    @ApiModelProperty(value = "外部来源订单商品id", example = "8878", required = true, position = 3)
    private String clientOrderGoodsId;
    @ApiModelProperty(value = "供应商Id", example = "72", position = 5)
    private Integer vendorId;
    @ApiModelProperty(value = "商品名称", example = "防触电紧急救援钩", position = 5)
    private String name;
    @ApiModelProperty(value = "品牌", example = "电之虹", position = 5)
    private String brand;
    @ApiModelProperty(value = "型号", example = "绝缘救援钩35KV", position = 5)
    private String model;
    @ApiModelProperty(value = "规格", example = "规格", position = 5)
    private String spec;
    @ApiModelProperty(value = "数量", example = "5", required = true, position = 4)
    private Double num;
    @ApiModelProperty(value = "单位", example = "个", position = 5)
    private String unit;
    @ApiModelProperty(value = "包装数量", example = "5", position = 5)
    private Double packageNum;
    @ApiModelProperty(value = "包装单位", example = "个", position = 5)
    private String packageUnit;
    @ApiModelProperty(value = "货期", example = "8", position = 5)
    private Integer delivery;
    @ApiModelProperty(value = "金税编码", example = "金税编码", position = 5)
    private String goldenTax;
    @ApiModelProperty(value = "税率", example = "0.16", position = 5)
    private Double taxRate;
    @ApiModelProperty(value = "运费税率", example = "0.06", position = 5)
    private Double taxRateFreight;
    @ApiModelProperty(value = "税前商品单价", example = "301.72414", position = 5)
    private Double pretaxPrice;
    @ApiModelProperty(value = "税后商品单价", example = " 350.0000024", position = 5)
    private Double price;
    @ApiModelProperty(value = "税前运费", example = "0", position = 5)
    private Double pretaxFreight;
    @ApiModelProperty(value = "税后商品运费共计", example = "1750", position = 5)
    private Double amount;
    @ApiModelProperty(value = "备注", example = "备注", position = 5)
    private String memo;
    @ApiModelProperty(value = "物料编码", position = 5)
    private String sku;

    @ApiModelProperty(value = "区域", position = 5)
    private String region;
    @ApiModelProperty(value = "公司", position = 5)
    private String company;
    @ApiModelProperty(value = "仓库", position = 5)
    private String warehouse;
    @ApiModelProperty(value = "扩展字段", position = 5)
    private String extendsAttr;


    public CustomerOrderGoodsVo toCustomerOrderGoodsVo() {

        CustomerOrderGoodsVo.CustomerOrderGoodsVoBuilder goodsBuild = CustomerOrderGoodsVo.builder();
        goodsBuild.goods_id(getGoodsId())
                .goods_src(String.valueOf(getSrc()))
                .client_order_goods_id(getClientOrderGoodsId())
                .name(getName())
                .brand(getBrand())
                .model(getModel())
                .spec(getSpec())
                .num(BigDecimal.valueOf(Optional.ofNullable(getNum()).orElse(0d)))
                .unit(getUnit())
                .package_num(BigDecimal.valueOf(Optional.ofNullable(getPackageNum()).orElse(0d)))
                .delivery(BigDecimal.valueOf(Optional.ofNullable(getDelivery()).orElse(0)))
                .golden_tax(getGoldenTax())
                .tax_rate(BigDecimal.valueOf(Optional.ofNullable(getTaxRate()).orElse(0d)))
                .freight_rate(BigDecimal.valueOf(Optional.ofNullable(getTaxRateFreight()).orElse(0d)))
                .pretax_price(BigDecimal.valueOf(Optional.ofNullable(getPretaxPrice()).orElse(0d)))
                .price(BigDecimal.valueOf(Optional.ofNullable(getPrice()).orElse(0d)))
                .pretax_freight(BigDecimal.valueOf(Optional.ofNullable(getPretaxFreight()).orElse(0d)))
                .amount(BigDecimal.valueOf(Optional.ofNullable(getAmount()).orElse(0d)))
                .memo(getMemo())
                .sku(getSku())
                .region(getRegion())
                .company(getCompany())
                .warehouse(getWarehouse())
                .extends_attr(getExtendsAttr());

        if (getVendorId() != null) {
            goodsBuild.vendor_organization_id(Utils.createSelecorFormat(String.valueOf(getVendorId()), "", UnitType.DEPARTMENT.getIndex()));
        }
        return goodsBuild.build();

    }

}
